#include <fstream>
#include <iostream>
using namespace std;
#define max_N 101
#define max_M 101
char water[max_N][max_M];
int N = 0;
int M = 0;
void dfs(int x,int y)
{
    water[x][y] = '.';
    for (int i = -1; i <= 1;++i)
        for (int j = -1; j <= 1;++j){
            int nx = x + i;
            int ny = y + j;
            if (nx >= 0 && ny >= 0&&nx<N&&ny<M&&water[nx][ny]=='W')
                dfs(nx, ny);
        }
}

int  main(){
    //fstream cin("test.txt");

    cin >> N >> M;
    for (int i = 0; i < N;++i)
        for (int j = 0; j < M;++j){
            cin >> water[i][j];
        }
    int res = 0;
    for (int i = 0; i < N;++i)
        for (int j = 0; j < M;++j){
            if(water[i][j]=='W'){
                dfs(i, j);
                res++;
            }
        }
    cout << res << endl;
    return 0;
}